package com.google.shop.product.search.service.impl;

import com.google.shop.product.common.utils.MR;
import com.google.shop.product.search.service.AmazonService;
import com.google.shop.product.search.vo.AmazonVO;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
/* loaded from: app.jar:BOOT-INF/classes/com/google/shop/product/search/service/impl/AmazonImpl.class */
public class AmazonImpl implements AmazonService {
    @Override // com.google.shop.product.search.service.AmazonService
    public MR FindAmazonPage(String name, Integer pageNum, @Value("${amazon.csm-hit}") String hit, @Value("${amazon.session-token}") String token) throws IOException {
        Element search;
        if (name == "" || name == null || (search = Jsoup.connect("https://www.amazon.com/s?k=" + name + "&page=" + pageNum).cookie("csm-hit", hit).cookie("ubid-main", "131-3828629-9319226").cookie("skin", "noskin").cookie("lc-main", "zh_CN").cookie("ad-privacy", "0").cookie("ad-id", "A-_UXFZoDkX9hoqBS1BU5n0").cookie("sp-cdn", "\"L5Z9:SG\"").cookie("session-id-time", "2082787201l").cookie("i18n-prefs", "USD").cookie("session-token", token).cookie("session-id", "147-4891102-7868643").timeout(30000).get().getElementById("search")) == null) {
            return MR.error("检索字段为空");
        }
        List<AmazonVO> amazonVOList = new ArrayList<>();
        Iterator<Element> it = search.getElementsByClass("s-line-clamp-2").iterator();
        while (it.hasNext()) {
            String text1 = it.next().getElementsByClass("a-text-normal").eq(0).text();
            AmazonVO amazonVO = new AmazonVO();
            amazonVO.setTitle(text1);
            amazonVOList.add(amazonVO);
        }
        int i = 0;
        Iterator<Element> it2 = search.getElementsByClass("s-image-fixed-height").iterator();
        while (it2.hasNext()) {
            amazonVOList.get(i).setImg(it2.next().getElementsByTag("img").attr("src"));
            i++;
        }
        for (AmazonVO amazonVO2 : amazonVOList) {
            System.out.println(amazonVO2);
        }
        if (amazonVOList.size() <= 0) {
            return MR.error("没有更多分页");
        }
        return MR.ok().put("amazonPage", (Object) amazonVOList);
    }
}
